﻿
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace project
{
    public partial class EmployeeAdd : Form
    {
        public EmployeeAdd()
        {
            InitializeComponent();
            Init();
        }
        public void Init()
        {
            string sql = "SELECT [DepartmentNo],[DepartName] FROM [dbo].[Department]";
            DataTable dt = DBHelper.GetTable(sql);
            foreach (DataRow item in dt.Rows)
            {
                this.comboBox1.Items.Add(item["DepartName"]);
            }
            this.comboBox1.SelectedIndex = 0;
        }


        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void Form5_FormClosing(object sender, FormClosingEventArgs e)
        {


        }

        private void EmployeeAdd_Load(object sender, EventArgs e)
        {
           
            
        }

        private void buttonAdd_Click(object sender, EventArgs e)
        {
            string sex;
            if (this.radioButton1.Checked)
            {
                sex = "男";
            }
            else
            {
                sex = "女";
            }
            string name= this.textBoxName.Text;
            int DepartmentId = this.comboBox1.SelectedIndex+1;
            string address = this.textBoxAddress.Text;
            string salary = this.textBoxSalary.Text;
            string phone = this.textBoxPhone.Text;
            string password = this.textBoxPassword.Text;
            string sql = "INSERT INTO [dbo].[AdminTable]([DepartmentNo],[AdminName],[Sex],[Password],[Salary],[Address],[Phone])VALUES({0},'{1}','{2}','{3}','{4}','{5}','{6}')";
            sql = string.Format(sql,DepartmentId,name,sex,password,salary,address,phone);
            if (DBHelper.ExecuteNonQuery(sql)>0)
            {
                MessageBox.Show("添加成功");
            }
            
            
        }
    }
}
